<?php

/**
 * View helper to generate links to public module resources.
 *
 * @author     Mon Zafra <monzee at gmail>
 * @copyright  (c)2009 Mon Zafra
 * @category   Mz
 * @package    Mz_Module
 * @subpackage Helper
 * @license    http://mz-project.googlecode.com/svn/trunk/LICENSE    MIT License
 * @version    SVN: $Id: Asset.php 48 2009-05-29 11:03:25Z monzee $
 */
class Modules_View_Helper_Asset extends Zend_View_Helper_Abstract
{
    /**
     * Generates a link.
     *
     * @param string $asset    Resource name
     * @param string $module   Needed if you render a partial outside the
     *                         current module since the module in the request
     *                         would be equal to the calling module
     * @return string
     */
    public function asset($asset, $module = null)
    {
        $asset = ltrim($asset, '/');

        // TODO: pull this from the bootstrap
        $front = Zend_Controller_Front::getInstance();
        $request = $front->getRequest();
        $module = null === $module ? $request->getModuleName() : $module;

        return $this->view->url(array($module, $asset), 'moduleAsset', true, false);
    }

}
